<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<!-- <el-form-item>
					<el-input v-model="filters.name" placeholder="设备IP"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary">查询</el-button>
				</el-form-item> -->
				<el-date-picker
			      v-model="exprotDate"
			      type="daterange"
      			  range-separator="至"
			      placeholder="请选择开始和结束时间">
			    </el-date-picker>
				<el-form-item v-show="my_permi.indexOf('weighAbnormal.export') > -1 || my_permi.indexOf('admin') > -1">
					<el-button type="primary" @click="exportT">导出</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="tableList" highlight-current-row v-loading="listLoading" style="width: 100%;" :height="clientHeight" >
			<el-table-column prop="vehicle_number" label="车牌号" width="100">
			</el-table-column>
			<el-table-column prop="actual_weight" label="吊秤重量" width="60">
			</el-table-column>
			<el-table-column prop="net_weight" label="地磅净重" width="60">
			</el-table-column>
			<el-table-column prop="weight_error" label="误差重量" width="60">
			</el-table-column>
			<el-table-column prop="weight_error_ratio" label="误差比值" width="60">
			</el-table-column>
			<el-table-column label="进厂地磅监控抓拍保存路径" width="160">
				<template slot-scope="scope">
					<img class="scope-img" @click="isZoom(scope.row.cap_m_path)" :src="scope.row.cap_m_path">
				</template>
			</el-table-column>
			<el-table-column label="出厂地磅监控抓拍保存路径" width="160">
				<template slot-scope="scope">
					<img class="scope-img" @click="isZoom(scope.row.cap_x_path)" :src="scope.row.cap_x_path">
				</template>
			</el-table-column>
			<el-table-column label="车牌识别车辆图片保存路径" width="160">
				<template slot-scope="scope">
					<img class="scope-img" @click="isZoom(scope.row.capvh_path)" :src="scope.row.capvh_path">
				</template>
			</el-table-column>
			<el-table-column prop="abnormal_information" label="异常信息">
			</el-table-column>
			<el-table-column prop="system_datetime" label="时间" width="80">
			</el-table-column>
			<el-table-column prop="remarks" label="备注">
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-pagination
				layout="prev, pager, next"
				@current-change="handleCurrentChange"
				:total="total"
				style="float:right;">
			</el-pagination>
		</el-col>

		<!-- 图片放大 -->
		<el-dialog title="展示图片" v-model="is_zoom_img" class="zoom-img-dialog" :close-on-click-modal="false">
			<img :src="zoom_img">
		</el-dialog>
	</section>
</template>

<script>
	import { weighAbnormal, BASEURL } from '@/api/api';
    import { mapState } from 'vuex'
	export default {
		data() {
			return {
				filters: {
					name: ''
				},
				tableList: [],
				total: 0,
				page: 1,
				listLoading: false,
				is_zoom_img: false,
				zoom_img: '',
				exprotDate: '',
			}
		},
        computed: {

            ...mapState(
                {
                  'my_permi': state => state.my_permi,
                  'clientHeight': state => state.clientHeight
                }
            )
        },
		methods: {
			router(path) {
				this.$router.push(path)
			},
			handleCurrentChange(val) {
				this.page = val;
				this.weigh_abnormal();
			},
			//获取设备警报信息
			weigh_abnormal() {
				this.listLoading = true;
				weighAbnormal(this.page).then((res) => {
					if(res.data.status.errCode == '10002'){
						sessionStorage.removeItem('token');
						this.$message({
							message: res.data.status.message,
							type: 'warning'
				        });
				        setTimeout(() =>{
				        	this.router({path: '/login'})
				        }, 1500);
						return;
					}
					this.total = res.data.data.total
					this.tableList = res.data.data.data
					this.listLoading = false
				});
			},
			isZoom(imgSrc) {
				this.zoom_img = imgSrc
				this.is_zoom_img = !this.is_zoom_img
			},
			exportT() {
				let startD = "";
				let overD = "";
				let firstDate = "";
				let secendDate = "";
				if(this.exprotDate){
					firstDate = new Date(this.exprotDate[0])
					secendDate = new Date(this.exprotDate[1])
				}else{
					firstDate = new Date();
					secendDate = new Date();
				}
				startD = firstDate.getFullYear() + '-' + (firstDate.getMonth()+1) + '-' + firstDate.getDate()
				overD = secendDate.getFullYear() + '-' + (secendDate.getMonth()+1) + '-' + secendDate.getDate()
				location.href=`${BASEURL}/WeighAbnormal/Export?token=${sessionStorage.token}&start_time=${startD}&end_time=${overD + ' 23:59:59'}&pageSize=${sessionStorage.getItem('pagesize')}`;
			},
		},
		mounted() {
			this.weigh_abnormal();
		}
	}

</script>

<style>
.scope-img{
	width: 210px;
	height: 40px;
	cursor: pointer;
	object-fit: cover;
	margin-top: 8px;
}
</style>